package com.px.user.mapper;

import com.px.user.entity.ConstT;
import com.px.user.entity.Sensi;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ConstTMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into const_t (code,name,start,end,value) values (#{code},#{name},#{start},#{end},#{value})")
    void insert(ConstT constT);

    @Update({"<script>",
            "update const_t",
            " <set>",
            "  <if test='code != null'>code=#{code},</if>",
            "  <if test='name != null'>name=#{name},</if>",
            "  <if test='start != null'>start=#{start},</if>",
            "  <if test='end != null'>end=#{end},</if>",
            "  <if test='value != null'>value=#{value},</if>",
            " </set>",
            "where id=#{id}",
            "</script>"})
    void update(ConstT constT);

    @Select("select * from const_t where id=#{id}")
    ConstT findById(Long id);

    @Select("select * from const_t where code=#{code}")
    ConstT findByCode(String code);

    @Select("select * from const_t")
    List<ConstT> findAll();

    @Delete("delete from const_t where id=#{id}")
    void delete(Long id);

    /**
     * 敏感词
     */
    @Insert("insert into sensi (txt) values (#{txt})")
    void insertSensi(Sensi sensi);
}
